﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class AnswerInChannelFormsController : ControllerBase
    {

        private readonly IAnswerInChannelFormAppService _app;
        public AnswerInChannelFormsController(IAnswerInChannelFormAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("answerInChannels/{answerInChannelId:Guid}/form")]
        public ActionResult<AnswerInChannelFormDto> Get([FromRoute] Guid answerInChannelId,[FromQuery] string include = "")
        {
            AnswerInChannelFormDto answerInChannelForm = _app.GetByAnswerInChannelId(answerInChannelId, include);
            return Ok(answerInChannelForm);
        }


        [HttpPut]
        [Route("forms/{id:Guid}")]
        public ActionResult<AnswerInChannelFormDto> Put([FromRoute] Guid id, [FromBody] AnswerInChannelFormUpdateDto dto)
        {
            AnswerInChannelFormDto answerInChannelForm = _app.Update(id, dto);
            return Ok(answerInChannelForm);
        }

        [HttpPost]
        [Route("answerInChannels/{answerInChannelId:Guid}/form")]
        public ActionResult<AnswerInChannelFormDto> Post([FromRoute] Guid answerInChannelId, [FromBody] AnswerInChannelFormCreateDto dto)
        {
            AnswerInChannelFormDto answerInChannelForm = _app.Add(answerInChannelId, dto);
            return CreatedAtAction(nameof(Get), new { id = answerInChannelForm.Id }, answerInChannelForm);
        }

        [HttpDelete]
        [Route("forms/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
